<template>
  <div class='finish_room'>
    <div class='finish_room2'>
        <div class="imgInfo" v-if="userImage!==''">
          <img :src="userImage" @click='delete_img'>
        </div>
        <div v-else>
            <el-upload :action="'/dev-api/service-system/system/user/uploadImage/'+uid" :file-list="fileList" :class="{disabled:uploadDisabled}" :headers="myheader" :on-success="uploadSuccess" :on-remove="handleRemove" list-type="picture-card">
             <span>{{textTip}}</span>
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </div>
    </div>
  </div>

</template>

<script >
import { updatedImg } from '@/filters'
import { getToken } from '@/utils/auth'

export default {
  data: function() {
    return {
      image: '',
      imgPhone: '',
      textTip: '',
      uploadDisabled: '',
      fileList: [],
      businessLicense: '',
      uid:this.$route.params.id
    }
  },
  props: ['userImage','userId'],
  computed: {
    myheader: function() {
      return {
        Authorization: `${getToken()}`
      }
    }
  },
  methods: {
    delete_img(item) {
      this.userImage = ''
    },
    handleRemove(file, fileList) {
      this.uploadDisabled = false
    },
    // 文件上传完成
    typeTip(obj) {
      this.$message.error(obj)
    },
    uploadSuccess(obj, file) {
      this.businessLicense = obj.fid
      this.uploadDisabled = true
      updatedImg(file, obj, this.typeTip)
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
.finish_room {
  .el-upload--picture-card {
    i {
      font-size: 12px;
    }
  }
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
.finish_room {
  width: 200px;
  height: 200px;
  line-height: 100px;
  display: inline-block;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  margin-right: 10px;
}

.finish_room2 {
  width: 100%;
  height: auto;
  display: flex;
  align-items: center;
  position: relative;
  .room_img {
    width: 200px;
    height: 200px;
    margin-right: 10px;
    position: relative;
    overflow: hidden;

    span {
      position: absolute;
      width: auto;
      height: auto;
      right: 5px;
      bottom: 3px;
    }
  }
  .imgInfo {
    position: absolute;
    left: 0;
    top: 0;
    width: 200px;
    height: 200px;
    background: #fff;
    border: 1px dashed #c0ccda;
    border-radius: 8px;
    z-index: 9;
    img {
      width: 100%;
      height: 100%;
    }
  }
}

.room_add_img {
  width: 100px;
  height: 98px;
  line-height: 98px;
  text-align: center;
  span {
    color: #999;
  }
  input {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    z-index: 99999;
    opacity: 0;
  }
}
</style>
